<div class="dialog">
    <table>
        <tbody>
        
            <tr class="prop">
                <td valign="top" class="name"><g:message code="purchase.serialNumber" default="Serial Number" />:</td>
                <td valign="top" class="value">${fieldValue(bean: purchaseInstance, field: "serialNumber")}</td>

                <td valign="top" class="name"><g:message code="purchase.date" default="Date" />:</td>
                <td valign="top" class="value"><g:formatDate date="${purchaseInstance?.date}" format="yyyy-MM-dd"/></td>

                <td valign="top" class="name"><g:message code="purchase.maker" default="Maker" />:</td>
                <td valign="top" class="value"><g:link controller="staff" action="show" id="${purchaseInstance?.maker?.id}">
                    ${purchaseInstance?.maker?.encodeAsHTML()}</g:link>
                </td>
            </tr>
            
            <tr class="prop">
                <td valign="top" class="name"><g:message code="purchase.dealer" default="Dealer" />:</td>
                <td valign="top" class="value"><g:link controller="dealer" action="show" id="${purchaseInstance?.dealer?.id}">${purchaseInstance?.dealer?.encodeAsHTML()}</g:link></td>

                <td valign="top" class="name"><g:message code="purchase.director" default="Director" />:</td>
                <td valign="top" class="value"><g:link controller="staff" action="show" id="${purchaseInstance?.director?.id}">${purchaseInstance?.director?.encodeAsHTML()}</g:link></td>
           
                <td valign="top" class="name"><g:message code="purchase.recordType" default="Record Type" />:</td>
                <td valign="top" class="value"><g:link controller="recordType" action="show" id="${purchaseInstance?.recordType?.id}">${purchaseInstance?.recordType?.encodeAsHTML()}</g:link></td>
            </tr>
            
        </tbody>
    </table>
</div>
<div class="list">
    <table>
        <thead>
            <tr>
                <th><g:message code="purchaseDetail.serialNumber" default="Serial Number" /></th>
                <th><g:message code="purchaseDetail.product" default="Product" /></th>
                <th><g:message code="purchaseDetail.unit" default="Unit" /></th>
                <th class="number"><g:message code="purchaseDetail.quantity" default="Quantity" /></th>
                <th class="number"><g:message code="purchaseDetail.price" default="Price" /></th>
                <th class="number"><g:message code="purchaseDetail.amount" default="Amount" /></th>
            </tr>
        </thead>
        <tbody>
        <g:each in="${purchaseInstance?.details?.sort{it?.serialNumber}}" status="i" var="purchaseDetailInstance">
            <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                <td>${fieldValue(bean: purchaseDetailInstance, field: "serialNumber")}</td>
                <td>${fieldValue(bean: purchaseDetailInstance, field: "product")}</td>
                <td>${fieldValue(bean: purchaseDetailInstance, field: "unit")}</td>
                <td class="number"><g:formatNumber number="${purchaseDetailInstance.quantity}" format="###,##0.00"/></td>
                <td class="number"><g:formatNumber number="${purchaseDetailInstance.price}" format="###,##0.00"/></td>
                <td class="number"><g:formatNumber number="${purchaseDetailInstance.amount}" format="###,##0.00"/></td>
            </tr>
        </g:each>
        </tbody>
        <tfoot>
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td class="number"><g:formatNumber number="${purchaseInstance?.details*.quantity.sum()}" format="###,##0.00"/></td>
                <td></td>
                <td class="number"><g:formatNumber number="${purchaseInstance?.details*.amount.sum()}" format="###,##0.00"/></td>
            </tr>
        </tfoot>
     </table>
</div>

